package com.xscha.tableforge.jooq.tables;

import org.jooq.*;
import org.jooq.Record;
import org.jooq.impl.DSL;
import org.jooq.impl.SQLDataType;
import org.jooq.impl.TableImpl;

import java.time.LocalDateTime;

/**
 * 操作日志表
 * 用于记录用户对数据的操作，包括增删改等操作
 */
public class OperationLogTable extends TableImpl<Record> {

    private static final long serialVersionUID = -1L;

    public static final OperationLogTable OPERATION_LOG = new OperationLogTable();

    /** 主键ID */
    public final TableField<Record, String> ID = createField(DSL.name("id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 用户ID */
    public final TableField<Record, String> USER_ID = createField(DSL.name("user_id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 空间ID */
    public final TableField<Record, String> SPACE_ID = createField(DSL.name("space_id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 表ID */
    public final TableField<Record, String> TABLE_ID = createField(DSL.name("table_id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 记录ID */
    public final TableField<Record, String> RECORD_ID = createField(DSL.name("record_id"), SQLDataType.VARCHAR.nullable(false), this);
    /** 操作类型 */
    public final TableField<Record, String> OPERATION_TYPE = createField(DSL.name("operation_type"), SQLDataType.VARCHAR(10).nullable(false), this);
    /** 旧数据 */
    public final TableField<Record, String> OLD_DATA = createField(DSL.name("old_data"), SQLDataType.CLOB, this);
    /** 新数据 */
    public final TableField<Record, String> NEW_DATA = createField(DSL.name("new_data"), SQLDataType.CLOB.nullable(false), this);
    /** IP地址 */
    public final TableField<Record, String> IP = createField(DSL.name("ip"), SQLDataType.VARCHAR(50), this);
    /** 用户代理 */
    public final TableField<Record, String> USER_AGENT = createField(DSL.name("user_agent"), SQLDataType.VARCHAR(500), this);
    /** 创建时间 */
    public final TableField<Record, LocalDateTime> CREATED_TIME = createField(DSL.name("created_time"), SQLDataType.LOCALDATETIME(3).nullable(false), this);

    private OperationLogTable() {
        super(DSL.name("operation_log"));
    }

    @Override
    public Schema getSchema() {
        return DSL.schema(DSL.name("public"));
    }

    @Override
    public UniqueKey<Record> getPrimaryKey() {
        return Keys.OPERATION_LOG_PKEY;
    }

    @Override
    public OperationLogTable as(String alias) {
        return new OperationLogTable().as(alias);
    }

    @Override
    public OperationLogTable as(Name alias) {
        return new OperationLogTable().as(alias);
    }
} 